<%@page import="org.ipo.mm.web.util.ConstantManager, java.util.Collection, org.ipo.mm.web.util.security.SecurityManager" %>
<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8" %>
<%@taglib prefix="l" uri="http://struts.apache.org/tags-logic" %>
<%@taglib prefix="b" uri="http://struts.apache.org/tags-bean" %>
<%@taglib prefix="h" uri="http://struts.apache.org/tags-html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%	String readOnlyStr = (String) session.getAttribute("readOnly");%>

<div id=tableCityTitle >
    <h1>
        <% if (readOnlyStr.equals("true")) {%>
        <b:message key="cities_show_read_mode"/>
        <%} else {%>
        <b:message key="cities_show_edit_mode"/>
        <%}%>
    </h1>
</div>
<%
            Collection<Integer> privileges = (Collection<Integer>) request.getSession().getAttribute(ConstantManager.SESSION_USER_PRIVILEGES);
%>
<div>
    <table  id="cityTable" class="display">
        <thead>
            <tr>
                <th><b:message key="cities_name"/></th>
                <th><b:message key="cities_zip"/></th>
                <th><b:message key="cities_region"/></th>
                <th><b:message key="cities_find_inst"/></th>
                <% if (readOnlyStr.equals("false")) {%>
                <th><b:message key="gen_action"/></th>
                <%}%>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th><b:message key="cities_name"/></th>
                <th><b:message key="cities_zip"/></th>
                <th><b:message key="cities_region"/></th>
                <th><b:message key="cities_find_inst"/></th>
                <% if (readOnlyStr.equals("false")) {%>
                <th><b:message key="gen_action"/></th>
                <%}%>
            </tr>
        </tfoot>
        <tbody>
            <l:iterate id="city" name="showCities.cities" scope="request">
                <tr>
                    <td>
                        <% if (readOnlyStr.equals("false")) {%>
                        <p class="link"
                           onclick="getHtmlAjax('<%= request.getContextPath()%>/protected/dispatch.do?method=showUpdateCityForm&cid=${city.id}','#cityDialog','#cityForm');">
                            <b:write name="city" property="name"/>
                        </p>
                        <%} else {%>
                        <p class="link"
                           onclick="getHtmlAjax('<%= request.getContextPath()%>/protected/dispatch.do?method=viewCityForm&cid=${city.id}','#cityDialog','#cityForm');">
                            <b:write name="city" property="name"/>
                        </p>
                        <%}%>
                    </td>
                    <td><span><b:write name="city" property="zipCode"/></span></td>
                    <td><span>${city.region.name}</span></td>
                    <td>
                        <h:link action="/protected/institution_search">
                            <h:param name="cid"  value="${city.id}"/>
                            <h:param name="readOnly"  value="true"/>    
                            <span>
                                <b:message key="cities_find_inst"/> - <b:write name="city" property="name"/>
                            </span>
                        </h:link>
                    </td>
                    <% if (readOnlyStr.equals("false")) {%>
                    <td nowrap="true">
                        <%if (privileges.contains(SecurityManager.DELETE_CITY_PRIVILEGE)) {%>
                        <h:link styleClass="delete"
                                action="/protected/dispatch?method=deleteCity"
                                paramId="cid"
                                paramName="city"
                                paramProperty="id"
                                onclick="return confirm('Are you sure you want to delete this item?/Da li ste sigurni da zelite da izbrisete ovaj entitet?')">
                            <b:message key="gen_delete"/>
                        </h:link>
                        <a href="#" class="displayNone" onclick=deleteCity(${city.id})><b:message key="gen_delete"/></a>
                        <%}%>
                    </td>
                    <%}%>
                </tr>
            </l:iterate>
        </tbody>
    </table>
</div>
<div id="cityDialog" class="dialog">
</div>
<script type="text/javascript">
    function cancelForm(){
        $(".dialog").dialog('close');
    }
</script>
